//
//  BQShopCarFifthCell.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/5/7.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQShopCarFifthCell.h"
#import "BQClickFoodView.h"
#import "BQShopingCarModel.h"
@interface BQShopCarFifthCell ()

@property (nonatomic,weak) BQClickFoodView *clickFoodView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *partner_priceLabel;

@end

@implementation BQShopCarFifthCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // 实例化clickFoodView
    BQClickFoodView *clickFoodView = [BQClickFoodView clickFoodView];
    
    _clickFoodView = clickFoodView;
    
    // 添加到cell的 contentView上
    [self.contentView addSubview:clickFoodView];
    
    // 约束
    [clickFoodView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self);
        
        make.right.offset(-10);
        
        make.width.mas_equalTo(84);
        
        make.height.mas_equalTo(27);
        
    }];
    
    // 添加clickFoodView的监听
    [clickFoodView addTarget:self action:@selector(didClickFoodView:) forControlEvents:UIControlEventValueChanged];
    
}

#pragma mark - 监听点击 -
- (void)didClickFoodView:(BQClickFoodView *)foodView {
    
    
    // clickFoodView上显示的数字和 rightModel中的count绑定起来
    //    _rightModel.count = foodView.count;
    
    FMDatabase *db = [[FMDatabase alloc] initWithPath:localDBPath];
    [db open];
    
    [db executeUpdate:@"update BeeQuick set count = ? where id = ?",[NSString stringWithFormat:@"%zd",foodView.count],_model.id];
    
    
    
    [db close];
    
    
    // 发出通知
    [[NSNotificationCenter defaultCenter] postNotificationName:kShopingCarNotification object:nil];
    
    
    
}

-(void)setModel:(BQShopingCarModel *)model{
    
    _model = model;
    
    _nameLabel.text = model.name;
    
    _partner_priceLabel.text = model.partner_price;
    
    _clickFoodView.count = model.count;
    
}



@end
